package com.weigee.ktv.presenter.adapter.rv

import android.os.Bundle
import android.view.LayoutInflater
import com.bumptech.glide.Glide
import com.linde.library.activities.MyFragmentActivity
import com.linde.library.adapter.BaseRvAdapter
import com.linde.library.adapter.SimpleViewHolder
import com.weigee.ktv.R
import com.weigee.ktv.model.enums.ImagePreLoad
import com.weigee.ktv.model.enums.WeigeeHost
import com.weigee.ktv.view.fragment.SupermarketShoppingListFragment
import kotlinx.android.synthetic.main.adapter_all_supermarket.view.*

/**
 * Created by linde on 2017/5/28.
 *<p/>
 */
class AllSupermarketAdapter : BaseRvAdapter<String>()
{
    override fun onCreateViewHolder(parent: android.view.ViewGroup?, viewType: Int): SimpleViewHolder
    {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.adapter_all_supermarket, parent, false)
        return com.linde.library.adapter.SimpleViewHolder(view)
    }

    override fun onBindViewHolder(holder: SimpleViewHolder?, position: Int)
    {
        holder ?: return
        Glide.with(holder.itemView.context).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(holder.itemView.iv_supermarket_logo)
        Glide.with(holder.itemView.context).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(holder.itemView.iv_location)
        // 点击打开超市
        holder.itemView.setOnClickListener({ v ->
            val bundle = Bundle()
            bundle.putInt("shopId", 1)// todo 超市id
            MyFragmentActivity.start(v.context, SupermarketShoppingListFragment::class.java, bundle)
        })
    }

    override fun getItemCount(): Int
    {
        return 10
        // todo 这个需要改回来
    }
}